<template>
  <el-dialog title="审批档案" :visible.sync="dialogVisible" width="40%">
    <el-table :data="tableList" stripe max-height="500" row-key="id">
      <el-table-column prop="fileName" label="文件类型" align="center" show-overflow-tooltip />
      <el-table-column prop="originalFileName" label="文件名称" align="center" show-overflow-tooltip>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        width="120"
      >
        <template #default="{ row }">
          <!-- @click="approveHandle(row)" -->
          <el-button
            type="text"
            icon="el-icon-view"
            title="预览"
            @click="filePreview(row)"
          ></el-button>
          <el-button
            type="text"
            icon="el-icon-download"
            class="table-button-size"
            title="下载"
            @click="download(row)"
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false" type="primary">关 闭</el-button>
    </span>
  </el-dialog>
</template>
<script>
import { getProcessFile, download } from '@/api/designingScheme'

export default {
  name: 'ApprovalFile',
  data () {
    return {
      tableList: [],
      // 查询参数
      queryParams: {
        processId: ''
      },
      dialogVisible: false
    }
  },
  methods: {
  async  open (processId) {
      this.dialogVisible = true
      this.queryParams.processId = processId
      const res = await getProcessFile(this.queryParams)
      this.tableList = res.data
    },
     filePreview (item) {
      this.$filePreview(item)
    },
        // 下载文件
    download (row) {
      download(row.fileId).then((res) => {
        console.log(res)
        const blob = new Blob([res.res])
        const url = window.URL.createObjectURL(blob)
        const link = document.createElement('a') // 创建a标签
        link.href = url
        link.download = row.originalFileName // 重命名文件
        link.click()
        URL.revokeObjectURL(url) // 释放内
      })
    }
  }
}
</script>
